package com.mryang.ladder;

import java.util.Scanner;

/**
 * @ClassName L1_20
 * @Description TODO 帅到没朋友
 * @Author Genius
 * @Date 2021/2/3 13:08
 */
public class L1_20 {
    public static void main(String[] args) {
        Scanner scr = new Scanner(System.in);

        int friendCircleNumber = scr.nextInt(); // 朋友圈个数
        int[] friendCircle = new int[friendCircleNumber]; // 朋友圈
        int[][] friendId = new int[1000][];

        // 输入
        // 朋友圈及对应朋友id
        for (int i = 0; i < friendCircleNumber; i++) {
            friendCircle[i] = scr.nextInt();
            for (int j = 0; j < friendCircle[i]; j++) {
                friendId[i][j] = scr.nextInt();
            }
        }
        // 要查询的人
        int selectFriendNumber = scr.nextInt();
        int[] selectFriendId = new int[selectFriendNumber];
        System.out.println();
        for (int i = 0; i < selectFriendNumber; i++) {
            selectFriendId[i] = scr.nextInt();
        }

        // 查询帅到没朋友的人
        int[] noFriendId = new int[selectFriendNumber]; // 存储没朋友的人的id
        for (int i = 0; i < selectFriendNumber; i++) { //
            for (int j = 0; j < friendCircleNumber; j++) { // 第j个朋友圈
                for (int k = 0; k < friendCircle.length; k++) { // 第j个朋友圈中的人
                    if(selectFriendId[i] == friendId[j][k]){
                        noFriendId[i] = selectFriendId[i];
                    }
                }
            }
        }

        for (int noFriend : noFriendId) {
            System.out.print(noFriend+" ");
        }


    }
}
